/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import comunicacao.RmiClient;
import entities.Chair;
import entities.Lugar;
import entities.Teatro;
import java.util.ArrayList;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Leonardo Lino
 */
@ManagedBean
@RequestScoped
public class SelectedTeatro {

    private String selected;
    private int numRows = 30;
    private int numColumns = 24;
    private ArrayList<Chair> chairs;
 
    private Teatro teatro;

    /**
     * Creates a new instance of SelectedTeatro
     */
    public SelectedTeatro() {
    }
    
    public void preRender(){
        
    }
    
    @PostConstruct
    public void carregou(){
        FacesContext fc = FacesContext.getCurrentInstance();
        selected =
                (String) fc.getExternalContext().
                getRequestParameterMap().get("teatro");
        
        RmiClient rc = new RmiClient();
        teatro = rc.getTeatro(selected);
        buildChairs(teatro);
    }
    
    private void buildChairs(Teatro teatro){
        
        chairs = new ArrayList<Chair>();
        for (Lugar lug : teatro.getLugares()) {
           Chair ch = new Chair();
           ch.setId(lug.id);
           ch.setState(lug.state);
           
           if (lug.state== Lugar.STATE_FREE){
               ch.setColorString("green");
               ch.setStateString("free");
           } else if(lug.state== Lugar.STATE_RESERVED){
               ch.setColorString("yellow");
               ch.setStateString("reserved");
           }else if(lug.state== Lugar.STATE_BOUGHT){
               ch.setColorString("red");
               ch.setStateString("bought");
           }
           chairs.add(ch);
        }
    }

    public String passedParam() {
        FacesContext fc = FacesContext.getCurrentInstance();
        String str =
                (String) fc.getExternalContext().
                getRequestParameterMap().get("teatro");

        return str;
    }

    public String getSelected() {
        return selected;
    }

    public void setSelected(String selected) {
        this.selected = selected;
    }

    public int getNumRows() {
        return numRows;
    }

    public void setNumRows(int numRows) {
        this.numRows = numRows;
    }

    public int getNumColumns() {
        return numColumns;
    }

    public void setNumColumns(int numColumns) {
        this.numColumns = numColumns;
    }

    public Teatro getTeatro() {
        RmiClient rc = new RmiClient();
        teatro = rc.getTeatro(selected);
        
        return teatro;
    }

    public void setTeatro(Teatro teatro) {
        this.teatro = teatro;
    }

    public ArrayList<Chair> getChairs() {
        return chairs;
    }

    public void setChairs(ArrayList<Chair> chairs) {
        this.chairs = chairs;
    }
    
    
}
